﻿/******************************************************************************
 * Name         : EchoPacket.hpp
 * Author       : 671643387
 * Date         : 2015年9月21日
 * Description  :
 *****************************************************************************/

#ifndef LOGIN_SERVER_PACKET_ECHOPACKET_HPP_
#define LOGIN_SERVER_PACKET_ECHOPACKET_HPP_

#include <boost/bind.hpp>
#include <boost/pool/object_pool.hpp>
#include <common/packet/PacketIDs.hpp>
#include <common/packet/Packet.hpp>
#include <common/packet/PacketFactory.hpp>

namespace sxr
{
    namespace common
    {
        class EchoPacket : public Packet
        {
        public:
            EchoPacket(int id);
            virtual ~EchoPacket(void);
            virtual bool execute(Player* player);

        public:
            const char* getMessage(void) { return payload_.message; }
            void copy(const char* msg);

        private:
            struct
            {
                struct _stHead head;
                char message[28];
            }payload_;                  // 包体
        };


        class EchoPacketFactory : public PacketFactory
        {
        public:
            EchoPacketFactory(void){}
            virtual ~EchoPacketFactory(void){}

        public:
            virtual PacketPtr create(void)
            {
                return PacketPtr(pool_.construct(PACKET_ID_ECHO),
                    boost::bind(&EchoPacketFactory::destroyPacket, this, _1));
            }

            virtual int getId(void) { return PACKET_ID_ECHO; }

        private:
            void destroyPacket(EchoPacket* packet) { pool_.destroy(packet); }

		private:
			boost::object_pool<EchoPacket> pool_;
        };


        class EchoPacketHandler
        {
        public:
            static bool execute(EchoPacket* packet, Player* player);
        };
    }
}

#endif /* LOGIN_SERVER_PACKET_ECHOPACKET_HPP_ */
